package com.yisu.expressway.customService.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.umeng.socialize.utils.Log;
import com.yisu.expressway.R;
import com.yisu.expressway.customService.VoiceAssistantActivity;
import com.yisu.expressway.customService.model.ServiceModule;
import com.yisu.expressway.model.ServiceDistrictObj;
import com.yisu.expressway.service_district.ShopDetailActivity;
import com.yisu.expressway.utils.DisplayUtil;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/10/5 0005.
 */

public class InfoTypeAdapter extends  RecyclerView.Adapter<InfoTypeAdapter.ShopViewHolder> {


    ServiceModule[] mData;
    private Activity mContext;

    public InfoTypeAdapter(Activity context,ServiceModule[] dataArray){
        this.mContext = context;
        this.mData = dataArray;
        notifyDataSetChanged();
    }


    @Override
    public ShopViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View mView = LayoutInflater.from(mContext).inflate(R.layout.item_text_above_pic, parent, false);
        return new ShopViewHolder(mView);
    }

    @Override
    public void onBindViewHolder(ShopViewHolder holder, int position) {

        if(mData.length <= position ){
            return;
        }

//        adjustModuleWidth(holder.mIv_logo);

        final ServiceModule item = mData[position];

        holder.mIv_logo.setImageResource(item.get_img_Id());
        if(item.getString_Id() != -1) {
            holder.mTv_title.setText(item.getString_Id());
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                VoiceAssistantActivity.launch(mContext,item.getCategory_Id());
            }
        });
    }


    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.length;
    }

    class ShopViewHolder extends RecyclerView.ViewHolder {

        @Bind(R.id.iv_pic) ImageView mIv_logo;
        @Bind(R.id.tv_module_name) TextView mTv_title;


        public ShopViewHolder(View itemView){
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }


    protected void adjustModuleWidth(View view){
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        int size = DisplayUtil.dip2px(mContext,84);
        lp.width = size;
        lp.height = size;
        view.setLayoutParams(lp);
    }
}
